home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / prospero / PRM / src / testprog / timesend.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-15  |  2.3 KB  |  101 lines

  1. /*
  2.  * Copyright (c) 1992, 1993 by the University of Southern California
  3.  *
  4.  * For copying and distribution information, please see the files
  5.  * <prm-copyr.h>.
  6.  */
  7.  
  8. #include <prm-copyr.h>
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <sys/time.h>
  13. #include <sys/resource.h>
  14. #include <sys/times.h>
  15.  
  16. #define  MAIN_PROG
  17. #include <comm.h>   /*     This file defines certain constants, and declares
  18.             some global variables used by the message passing
  19.             routines.  */
  20.  
  21. #ifdef HPUX
  22. #   define srandom srand
  23. #   define random rand
  24. #endif
  25.  
  26. #ifndef RNEIGH
  27. #   define RNEIGH(x,tot)    (x<tot)?x+1:1 /* right neighbor of x in the ring */
  28. #endif
  29.  
  30. #define MAXTIME 12                        /* Maximum computation time in sec.*/
  31. #define INT_SZ sizeof(int)
  32. #define SENDTO_PORT 1                     /* Port_id on destination task */
  33. #define RCVON_PORT  1                     /* Port on which to rcv messages */
  34.  
  35.  
  36. char *progname;
  37.  
  38. main(argc, argv)
  39. int argc;
  40. char **argv;
  41. {
  42.   int ntasks, my_tid, arraysize;
  43.   int time_dcrmt, timeleft, iter_cnt;
  44.   int sendto_task, nbytes, rbytes;
  45.   int time_secs, time_usecs;
  46.   double time;
  47.   float *a;
  48.   char fname[32];
  49.   struct rusage rusage1, rusage2;
  50.   FILE *ifd, *ofd;
  51.   register int i;
  52.   struct timeval tp1, tp2;
  53.   struct timezone tzp;
  54.  
  55.   init_task(argv);    /* Initialization is required for all tasks in every
  56.              application */
  57.  
  58.   pfs_debug=0;
  59.   my_tid = gettid(); 
  60.   if (my_tid == -1) {
  61.     io_printf(" task could not get its tid!", (char *)0);
  62.     exit(1);
  63.   }
  64.  
  65.   if( (ifd = fopen("timesend.in", "r")) == NULL) {
  66.     perror("fopen");
  67.     exit(1);
  68.   }
  69.   fscanf(ifd, "%d %d", &arraysize, &iter_cnt);
  70.   a = (float *)calloc(arraysize, sizeof(float));
  71.   nbytes = sizeof(float) * arraysize;
  72.  
  73.   if (my_tid == 1) { 
  74.     vsend(2, SENDTO_PORT, ANY_TAG, a, 4); 
  75.  
  76.     gettimeofday(&tp1, &tzp);  
  77.     for (i = 1; i<= iter_cnt; i++) 
  78.       vsend(2, SENDTO_PORT, ANY_TAG, a, nbytes); 
  79.     gettimeofday(&tp2, &tzp);
  80.  
  81.  
  82.     time = ((double)(tp2.tv_sec - tp1.tv_sec)) +
  83.              ((double)(tp2.tv_usec - tp1.tv_usec)) / 1.0E+6;
  84.     sprintf(fname, "send_timings_%d", nbytes);
  85.     ofd = fopen(fname, "a");
  86.     fprintf(ofd, "%d\t %f \n", iter_cnt, time);
  87.     fclose(ofd);
  88.   }
  89.  
  90.   else {
  91.     vrecv(ANY_TASK, RCVON_PORT, ANY_TAG, a, 4);
  92.  
  93.     for (i=1; i<= iter_cnt; i++) 
  94.       vrecv(ANY_TASK, RCVON_PORT, ANY_TAG, a, nbytes);
  95.   }
  96.  
  97.   io_printf("done", (char *)0);
  98.   exit(0);
  99. }
  100.  
  101.